<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/2 0002
 * Time: 下午 2:28
 */
namespace app\admin\model;

use think\Model;

class Admin extends Model {

    protected $autoWriteTimestamp = true;

    public function groups(){
        return $this->belongsToMany('AuthGroup','auth_group_access','group_id','u_id');
    }

    public static function isRegister($mobile){
        $result = self::get(['mobile'=>$mobile]);
        return $result;
    }

    public static function checkPassword($mobile,$password){
        $result = self::get(['mobile'=>$mobile]);
        if($password != $result->password){
            return false;
        }
        return $result;
    }

    public static function registerAdmin($uid,$name,$mobile,$password){
        $data = ['u_id'=>$uid,'name'=>$name,'mobile'=>$mobile,'password'=>$password];
//        print_r($data);die;
        return self::create($data);
    }

    public static function getAdminAll($page,$limit){
        $data = self::with('groups')->paginate($limit,true,['page'=>$page]);
        $count = $data->count();
        return ['data'=>$data,'count'=>$count];
    }

    public static function updateAdminInfo($data){
        return self::update($data);
    }

}